import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.MultimediaInfo;

public class VideoDuration_递归 {

	public void getVideoDuration(String path) {
		
		File[] files = new File(path).listFiles();

		Encoder encoder = new Encoder();
		MultimediaInfo multimediaInfo;

		long totalTime = 0L;
		long duration = 0L;

		for (int i = 0; i < files.length; i++) {
			// here, the format of video can be changed, JAVE upports dozens of formats
			String tfileName=files[i].toString();
			if (!files[i].isDirectory() && (tfileName.endsWith(".wmv") || tfileName.endsWith(".flv"))) {
				try {
					multimediaInfo = encoder.getInfo(files[i]);
					duration = multimediaInfo.getDuration();
					totalTime += duration;
				} catch (EncoderException e) {
					e.printStackTrace();
				}
			}
		}

		TimeZone.setDefault(TimeZone.getTimeZone("GMT+00:00")); // January 1, 1970, 00:00:00 GMT(can be found in
																// Date.class)
		Date date = new Date(totalTime);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
		System.out.println(simpleDateFormat.format(date) + "\t"+path);
	}

	public static void main(String[] args) {
		String filePath = "G:\\sp视频\\new\\框架\\javaSE\\day01";
		VideoDuration_递归 videoDuration = new VideoDuration_递归();
		videoDuration.getVideoDuration(filePath);
	}
}